#!/bin/bash

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

# 日志输出
function logout()
{
	# 格式化日志输出
	MSG="`date +"%Y-%m-%d %H:%M:%S | INFO     | resize_parted |"` $1"
	echo $MSG
	echo $MSG >> /var/log/resize_parted.log
}

function resize_parted()
{
    logout 扩展文件系统分区
    RP=$(mount | grep '/ ' | awk -F ' ' '{print$1}')
    logout "文件系统分区 $RP"
    sudo resize2fs $RP
    logout 清理执行脚本
    sudo systemctl disable resize-parted.service
    sudo rm -f /var/resize_parted.sh
    # 增加swap
    sudo fallocate -l 2G /swapfile
    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
    sudo swapon /swapfile
}

resize_parted
